package com.chandra.pos.order.dao;

import com.chandra.pos.order.dao.entity.OrderEntity;
import com.chandra.pos.order.dao.entity.OrderStatus;
import org.joda.time.DateTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Admin on 8/14/14.
 */
@Transactional(readOnly = true)
public interface OrderRepository extends JpaRepository<OrderEntity, Long> {


    @Query("SELECT p FROM OrderEntity p WHERE p.status = :orderStatus and  p.orderDate between :startDate and :endDate")
    public Page<OrderEntity> searchOrder(@Param("orderStatus") OrderStatus orderStatus, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);

    @Query("SELECT p FROM OrderEntity p WHERE p.status = :orderStatus ")
    public Page<OrderEntity> searchOrder(@Param("orderStatus") OrderStatus orderStatus, @Param("startDate") Pageable pageable);


    Page<OrderEntity> findByOrderDateBetween(DateTime startDate, DateTime endDate, Pageable request);
}
